package org.com.blbl.sortHotTopicTop5;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.com.blbl.bean.BiliSortBean;

import java.io.IOException;

public class SortHotTopicTop5Mapper extends Mapper<LongWritable, Text, BiliSortBean, Text> {

    //创建输出对象
    private BiliSortBean outKey = new BiliSortBean();
    private Text outValue = new Text();

    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        //读取一行数据进行切割
        String[] fields = value.toString().split("\t");
        //获得分区
        String partition = fields[0];
        //获得小分区
        String smallPartition = fields[1];
        //获得小分区数量
        long num = Long.parseLong(fields[2]);
        //填充数据
        outKey.set(num);
        outValue.set(partition+"\t"+smallPartition);
        //输出结果
        context.write(outKey, outValue);

    }
}
